<?php

namespace Admin\Controller;

use Think\Controller;
use Think\Page;

class MemberController extends Controller {

    public function __construct() {
        parent::__construct();
        session("[start]");
        if (!isset($_SESSION['admininfo']) || $_SESSION['admininfo']['id'] < 1) {
            $this->redirect('Login/index');
        }
    }

    /**
     * 查询会员游戏，区服，及充值信息
     * 
     */
    public function index() {
        //var_dump($_POST);
        $game_id = $_REQUEST['game_id'] ? intval($_REQUEST['game_id']) : 0;
        $area_num = $_REQUEST['area_num'] ? intval($_REQUEST['area_num']) : 0;
        $refer = $_REQUEST['refer'] ? intval($_REQUEST['refer']) : 0;
        $uname = $_REQUEST['uname'] ? intval($_REQUEST['uname']) : 0;
        $keywords = $_REQUEST['keywords'] ? I('request.keywords') : '';
        $dt1 = $_REQUEST['data_start'] ? I('request.data_start') : '';
        $dt2 = $_REQUEST['data_end'] ? I('request.data_end') : '';


        $userModel = new \Admin\Model\UserModel();
        $user = $userModel->getUserList($game_id, $area_num, $refer, $uname, $keywords, strtotime($dt1), strtotime($dt2));
        $count = count($user);
        $Page = new Page($count, 10); // 实例化分页类 传入总记录数
        $show = $Page->show(); // 分页显示输出
        $list = $userModel->getUserList($game_id, $area_num, $refer, $uname, $keywords, strtotime($dt1), strtotime($dt2), $Page->firstRow, $Page->listRows);


        //初始化游戏列表
        $gameModel = new \Admin\Model\GameModel();
        $gamelist = $gameModel->getGameList();


        //渠道来源
        $cpsModel = M("cps_member");
        $cpslist = $cpsModel->where("pid<>0 and refer<>0")->select();
        for ($i = 0; $i < count($list); $i++) {
            for ($j = 0; $j < count($cpslist); $j++) {
                $temp = explode(',', $cpslist[$j]['refer']);
                if (in_array($list[$i]['register_type'], $temp)) {
                    $list[$i]['refername'] = $cpslist[$j]['username'];
                }
            }
        }

        //根据game_id,area_num,uid算出用户的充值总金额
        $payModel = new \Admin\Model\PaylogModel();
        $paylist = $payModel->getFormatList($list);
        //var_dump($list);
        $this->assign('gamelist', json_encode($gamelist));
        $this->assign('game_id', $game_id);
        $this->assign('area_num', $area_num);
        $this->assign('keywords', $keywords);
        $this->assign('uname', $uname);
        $this->assign('dt1', $dt1);
        $this->assign('dt2', $dt2);
        $this->assign('list', $paylist); // 赋值数据集
        $this->assign('page', $show); // 赋值分页输出
        $this->display();
    }

}
